package com.woniu.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.woniu.entity.Goods;
import com.woniu.utils.MyPage;
import com.woniu.vo.GoodsVo;
import com.woniu.vo.QueryVo;
import com.github.pagehelper.PageHelper;
import com.woniu.dao.GoodsMapper;

@Transactional
@Service
public class GoodsService {
	@Autowired
	private GoodsMapper goodsMapper;

	public GoodsMapper gegoodsMapper() {
		return goodsMapper;
	}
	
	public List<Map> getProductList(int pageSize, int startIndex, String pname, String sellername, String productstatus,
			String starttime, String endingtime) {
		// TODO Auto-generated method stub
		System.out.println("TGoodsService层获取productList：" + goodsMapper.getProductList(pageSize, startIndex, pname,
				sellername, productstatus, starttime, endingtime));
		List<Map> listtest = goodsMapper.getProductList(pageSize, startIndex, pname, sellername, productstatus,
				starttime, endingtime);
		for (Map s : listtest) {
			System.out.println(s.get("starttime"));
		}

		return listtest;
	}


	public int getDataCount(String pname, String sellername, String productstatus, String starttime,
			String endingtime) {
		// TODO Auto-generated method stub
		return goodsMapper.getGoodsCount(pname, sellername, productstatus, starttime, endingtime);
	}


	public int updateStatusOff(String productId) {
		// TODO Auto-generated method stub
		return goodsMapper.switchStatusOff(productId);
	}


	public int updateStatusOn(String productId) {
		// TODO Auto-generated method stub
		return goodsMapper.switchStatusOn(productId);
	}
	
	
	public MyPage<QueryVo> selectByConds(GoodsVo gv) {
		// --查询
		int count = goodsMapper.findCount(gv);
		if (count == 0) {
			count = 1;
		}
		PageHelper.startPage(gv.getPageNum(), gv.getPageSize());
		List<QueryVo> list = goodsMapper.selectAllGoods(gv);
		MyPage<QueryVo> page = new MyPage<QueryVo>(count, gv.getPageSize(), list);
		return page;
	}

	public QueryVo selectGoodsById(Integer gid) {
		
		return goodsMapper.findGoodsById(gid);
	}

	public void updateGoodsById(Integer gid,Date uploadtime,String goodstatus) {
		goodsMapper.changeGoodsById(gid,uploadtime,goodstatus);
	}

	public void deleteById(int gid) {
		goodsMapper.deleteByPrimaryKey(gid);
	}

}